package cn.beforedark.yygh.hosp.controller.user;

import cn.beforedark.yygh.common.result.R;
import cn.beforedark.yygh.dto.hosp.HospitalQueryDto;
import cn.beforedark.yygh.hosp.service.HospitalService;
import cn.beforedark.yygh.model.hosp.Hospital;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * /user/hosp/hospital
 */
@RestController
@RequestMapping("/user/hosp/hospital")
public class UserHospitalController {

    @Autowired
    private HospitalService hospitalService;


    /**
     * 分页查询医院列表
     *
     * @param page            page
     * @param size            size
     * @param hospitalQueryVo 查询参数
     * @return co
     */
    @GetMapping("/list/{page}/{size}")
    public R getHospitalPage(@PathVariable("page") Integer page,
                             @PathVariable("size") Integer size,
                             HospitalQueryDto hospitalQueryVo) {
        Page<Hospital> hosptialPage = hospitalService.getHosptialPage(
                page, size, hospitalQueryVo);
        return R.ok().data("list", hosptialPage.getContent()).data("total", hosptialPage.getTotalPages());
    }

    /**
     * 医院名称模糊查询
     *
     * @param hosname hosname
     * @return list列表
     */
    @GetMapping("/hosname")
    public R findByName(String hosname) {
        List<Hospital> hospitalList = hospitalService.findByName(hosname);
        return R.ok().data("list", hospitalList);
    }

    /**
     * hoscode 查医院
     *
     * @param hoscode hoscode
     * @return vo
     */
    @GetMapping("/detail/{hoscode}")
    public R getHospitalDetail(@PathVariable String hoscode) {
        Hospital hospital = hospitalService.getHospitalDetail(hoscode);
        return R.ok().data("hospital", hospital);
    }
}
